package com.lineage.data.item_etcitem.add;

import com.lineage.data.executor.ItemExecutor;
import com.lineage.server.datatables.DollPowerTable;
import com.lineage.server.datatables.ItemPowerUpdateTable;
import com.lineage.server.model.Instance.L1ItemInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.serverpackets.S_ItemStatus;
import com.lineage.server.serverpackets.S_ServerMessage;
import com.lineage.server.serverpackets.ServerBasePacket;
import com.lineage.server.templates.L1Doll;
import com.lineage.server.templates.L1ItemPowerUpdate;
import com.lineage.server.utils.log.PlayerLogUtil;
import java.sql.Timestamp;

public class Item_Protection extends ItemExecutor {
  public static ItemExecutor get() {
    return new Item_Protection();
  }
  
  public void execute(int[] data, L1PcInstance pc, L1ItemInstance item) {
    L1ItemPowerUpdate info;
    L1Doll doll;
    int itemId = item.getItemId();
    int itemobj = data[0];
    L1ItemInstance item2 = pc.getInventory().getItem(itemobj);
    int targObjId = data[0];
    L1ItemInstance tgItem = pc.getInventory().getItem(targObjId);
    if (item2 == null)
      return; 
    if (item2.getproctect6()) {
      pc.sendPackets((ServerBasePacket)new S_ServerMessage(1300));
      return;
    } 
    switch (itemId) {
      case 92076:
        info = ItemPowerUpdateTable.get().get(item2.getItemId());
        if (info == null) {
          pc.sendPackets((ServerBasePacket)new S_ServerMessage(79));
          return;
        } 
        doll = DollPowerTable.get().get_type(item2.getItemId());
        if (doll == null) {
          pc.sendPackets((ServerBasePacket)new S_ServerMessage(2477));
          return;
        } 
        if (pc.getDoll(item2.getId()) != null) {
          pc.sendPackets((ServerBasePacket)new S_ServerMessage(1181));
          return;
        } 
        item2.setproctect6(true);
        pc.sendPackets((ServerBasePacket)new S_ItemStatus(tgItem));
        pc.sendPackets((ServerBasePacket)new S_ServerMessage(1308, item2.getLogName()));
        pc.getInventory().removeItem(item, 1L);
        娃娃保护("IP(" + pc.getNetConnection().getIp() + ")" + "玩家" + ":【 " + pc.getName() + " 】 " + "在" + "【 + " + 
            tgItem.getEnchantLevel() + " " + tgItem.getName() + "】- 附加娃娃保护成功," + "时间:" + "(" + 
            new Timestamp(System.currentTimeMillis()) + ")。");
        break;
    } 
  }
  
  public static void 娃娃保护(String info) {
    PlayerLogUtil.writeLog("[娃娃保护]", info);
  }
}
